<?php
/*
 * This file is part of the BooXtore Student project.
 *
 * (c) Francis Backeland f.backeland@gmail.com
 * (c) Laurine Chaplot chaplot.laurine@orange.fr
 * (c) Julien Dutot julien.dutot@gmail.com
 * (c) Romain Guillaume romain-guillaume@orange.fr
 * (c) Guillaume Paringaux g.paringaux@gmail.com
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code
 * 
 */

namespace BXTR\CoreBundle\EventListener;

use Symfony\Component\HttpKernel\Event\FilterControllerEvent;

abstract class AbstractKernelControllerEventListener 
{
    /**
     * Check if a controller is an object and not another callable.
     * From http://stackoverflow.com/a/11179521.
     *
     * @param mixed $controller
     */
    protected function isControllerAnObject($controller) 
    {
        return is_array($controller) && !$controller[0] instanceof ExceptionController;
    }

    /**
     * Check if the given tag is mentioned in the 'routing_tags' argument
     * of the routing entry.
     *
     * @param string $tag
     */
    protected function controllerHasTag(FilterControllerEvent $event, $tag) 
    {
        $tags = $event->getRequest()->get('tags');
        return is_array($tags) && in_array($tag, $tags);
    }
}
